package com.jtjrenren.android.taxi.driver.core.user.info;

import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.jtjrenren.android.taxi.driver.Constants;
import com.jtjrenren.android.taxi.driver.R;
import com.jtjrenren.android.taxi.driver.base.BaseActivity;
import com.jtjrenren.android.taxi.driver.bean.DriverInfo;
import com.jtjrenren.android.taxi.driver.bean.api.ApiDriverInfo;
import com.jtjrenren.android.taxi.driver.manger.AppManger;
import com.jtjrenren.android.taxi.driver.manger.api.ApiWorks;
import com.jtjrenren.android.taxi.driver.utils.IntentUtils;
import com.jtjrenren.android.taxi.driver.utils.UIHelper;
import com.library.utils.StringUtils;
import com.library.weiget.CustomFiveStars;
import com.nostra13.universalimageloader.core.ImageLoader;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/7/4.
 */
public class UserInfoActivity extends BaseActivity {
    @BindView(R.id.info_icon)
    ImageView iv_icon;
    @BindView(R.id.info_name)
    TextView tv_name;
    @BindView(R.id.info_carno)
    TextView tv_carno;
    @BindView(R.id.info_company)
    TextView tv_company;
    @BindView(R.id.info_serlevel)
    CustomFiveStars rb_level;
    @BindView(R.id.info_yhk_no)
    TextView tv_yhkno;
    @BindView(R.id.info_yhk_name)
    TextView tv_yhkname;
    @BindView(R.id.info_zfb_no)
    TextView tv_zfbname;
    @BindView(R.id.info_sernum)
    TextView tv_levelnum;
    @BindView(R.id.info_sjpm)
    TextView tv_driverpm;
    @BindView(R.id.title_title)
    TextView tv_title;

    private DriverInfo driver;


    @Override
    public int getLayoutID() {
        return R.layout.aty_user_info;
    }

    @Override
    public void init() {
        driver = AppManger.getInstance().driver;
        tv_title.setText("账户详情");
        getDriverInfo();
    }


    private void getDriverInfo() {
        if (driver == null) {
            Toast.makeText(this, "数据异常，请稍候再试...", Toast.LENGTH_SHORT).show();
            return;
        }

        ApiWorks.getDriverInfoDetails(driver.getWorkNo(), new ApiWorks.ResponseListener<ApiDriverInfo>() {
            @Override
            public void onResponse(ApiDriverInfo apiDriverInfo) {
                if (apiDriverInfo != null)
                    refreshDriverView(apiDriverInfo.getData());
            }
        });
    }

    private void refreshDriverView(ApiDriverInfo.DataEntity driverInfo) {
        ImageLoader.getInstance().displayImage(driverInfo.getHeadImg(), iv_icon, UIHelper.getDisplayOptions());
        tv_name.setText(driverInfo.getName());
        tv_carno.setText(driverInfo.getCarNo());
        tv_company.setText(driverInfo.getCompanyName());
        int level = Integer.parseInt(StringUtils.isEmpty(driverInfo.getServiceLevel()) ? "0" : driverInfo.getServiceLevel());
        rb_level.show(level);
        tv_yhkno.setText(driverInfo.getBank_Account());
        tv_yhkname.setText(driverInfo.getBank_BankCode());
        tv_zfbname.setText(driverInfo.getZFB_Account());
        tv_levelnum.setText(driverInfo.getSuccess() + "");

        tv_driverpm.setText(driverInfo.getRanking() == 0 ? "暂无排名" : driverInfo.getRanking() + "");
    }

    @OnClick(R.id.title_back)
    public void clickBack(){
        finish();
    }

    @OnClick(R.id.info_yhk)
    public void clickYhk() {
        IntentUtils.goBindPayPage(this, Constants.TYPE_PAY_YHK);

    }

    @OnClick(R.id.info_zfb)
    public void clickZfb() {
        IntentUtils.goBindPayPage(this, Constants.TYPE_PAY_ZFB);

    }

    @OnClick(R.id.info_tsdj)
    public void clickTsdj() {
        IntentUtils.goHtmlActivity(this, "提升等级", getString(R.string.url_tsdj));

    }

    @OnClick(R.id.info_xgmm)
    public void clickXgmm() {
        IntentUtils.goPwdChangedActivity(this);
    }
}
